#!/usr/bin/env python
# -*- coding: utf-8 -*-
# title       :
# author      : jarry

import sys
import os
import logging
from SceneCheckTool.checkScript.CheckBase import CheckBase

try:
    import maya.cmds as cmds
    import pymel.core as pm
    import jarryLibs.mayakit.MayaUtils as mu
    reload(mu)
except:
    pass

logging.basicConfig()
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class CheckShaderColorSpaceAttrs(CheckBase):
    def __init__(self):
        super(CheckShaderColorSpaceAttrs, self).__init__()
        pass
        self.shader_type = ["file", "aiImage"]

    def check_shader_color_space_attrs(self):
        error_list = []
        for node_type in self.shader_type:
            for node_name in cmds.ls(type=node_type):
                print node_name
                colorSpace = cmds.getAttr(node_name + ".colorSpace")
                if colorSpace == "Raw":
                    if not cmds.getAttr(node_name + ".ignoreColorSpaceFileRules"):
                        error_list.append(node_name)
        return error_list

    def check(self):
        error_list = self.check_shader_color_space_attrs()
        if error_list:
            result_log = u'Error:%s\n' % error_list
        else:
            result_log = u'Succeed:没有问题\n'

        return result_log

    def fix(self):
        error_list = self.check_shader_color_space_attrs()
        try:
            for node_name in error_list:
                cmds.setAttr(node_name + ".ignoreColorSpaceFileRules", True)
            result_log = u'Succeed:%s已经匹配\n' % error_list
            return result_log
        except:
            return u'Error:%s匹配失败\n' % error_list

